home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
-
- public class ProgressBar extends Canvas {
- private boolean progressBarVisible;
- private boolean percentMessageVisible;
- private Color completedPartColor;
- private Color remainingPartColor;
- private Color textColor;
- private String message;
- private int maximumValue;
- private int currentValue;
-
- public ProgressBar(int var1, Color var2, Color var3, Color var4, String var5) {
- if (var2 == null) {
- throw new IllegalArgumentException("null completedPartColor");
- } else {
- this.completedPartColor = var2;
- if (var3 == null) {
- throw new IllegalArgumentException("null remainingPartColor");
- } else {
- this.remainingPartColor = var3;
- if (var4 == null) {
- throw new IllegalArgumentException("null textColor");
- } else {
- this.textColor = var4;
- if (var1 <= 0) {
- throw new IllegalArgumentException("maximumValue < 0");
- } else {
- this.maximumValue = var1;
- if (var5 == null) {
- throw new IllegalArgumentException("null message");
- } else {
- this.message = var5;
- this.progressBarVisible = true;
- this.percentMessageVisible = true;
- }
- }
- }
- }
- }
- }
-
- public Color getCompletedPartColor() {
- return this.completedPartColor;
- }
-
- public void setCompletedPartColor(Color var1) {
- this.completedPartColor = var1;
- ((Component)this).repaint();
- }
-
- public Color getRemainingPartColor() {
- return this.remainingPartColor;
- }
-
- public void setRemainingPartColor(Color var1) {
- this.remainingPartColor = var1;
- ((Component)this).repaint();
- }
-
- public Color getTextColor() {
- return this.textColor;
- }
-
- public void setTextColor(Color var1) {
- this.textColor = var1;
- ((Component)this).repaint();
- }
-
- public boolean isPercentMessageVisible() {
- return this.percentMessageVisible;
- }
-
- public void setPercentMessageVisible(boolean var1) {
- this.percentMessageVisible = var1;
- ((Component)this).repaint();
- }
-
- public String getMessage() {
- return this.message;
- }
-
- public void setMessage(String var1) {
- this.message = var1;
- ((Component)this).repaint();
- }
-
- public void setMaximumValue(int var1) {
- this.maximumValue = var1;
- ((Component)this).repaint();
- }
-
- public int getMaximumValue() {
- return this.maximumValue;
- }
-
- public int getCurrentValue() {
- return this.currentValue;
- }
-
- public void setCurrentValue(int var1) {
- this.currentValue = var1;
- ((Component)this).repaint();
- }
-
- public double getPercentDone() {
- return (double)100.0F * (double)this.currentValue / (double)this.maximumValue;
- }
-
- public int changeBy(int var1) {
- int var2 = this.currentValue + var1;
- if (var2 > this.maximumValue) {
- var2 = this.maximumValue;
- } else if (var2 < 0) {
- var2 = 0;
- }
-
- this.currentValue = var2;
- ((Component)this).repaint();
- return this.currentValue;
- }
-
- public void reset() {
- this.currentValue = 0;
- ((Component)this).repaint();
- }
-
- public void paint(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- int var3 = var2.width;
- int var4 = var2.height;
- if (this.progressBarVisible) {
- var1.setColor(this.remainingPartColor);
- var1.fillRect(0, 0, var3, var4);
- if (this.currentValue > 0) {
- float var5 = (float)this.currentValue / (float)this.maximumValue;
- if (var5 > 1.0F) {
- var5 = 1.0F;
- }
-
- int var6 = (int)((float)(var3 - 2) * var5);
- var1.setColor(this.completedPartColor);
- var1.fillRect(1, 1, var6, var4 - 2);
- int var7 = (int)((double)100.0F * (double)var5);
- if (this.percentMessageVisible) {
- var1.setColor(this.textColor);
- var1.drawString(this.message + " " + var7 + "%", 4, var4 - 5);
- return;
- }
- }
- } else {
- var1.setColor(((Component)this).getParent().getBackground());
- var1.fillRect(0, 0, var3, var4);
- }
-
- }
-
- public void setProgressBarVisible(boolean var1) {
- this.progressBarVisible = var1;
- ((Component)this).repaint();
- }
-
- public boolean isProgressBarVisible() {
- return this.progressBarVisible;
- }
- }
-